/*     */ package net.sourceforge.appgen.support;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import net.sourceforge.appgen.model.Entity;
/*     */ import net.sourceforge.appgen.model.Field;
/*     */ import org.eclipse.jface.viewers.CellEditor;
/*     */ import org.eclipse.jface.viewers.CheckboxCellEditor;
/*     */ import org.eclipse.jface.viewers.ColumnViewer;
/*     */ import org.eclipse.jface.viewers.EditingSupport;
/*     */ import org.eclipse.jface.viewers.TableViewer;
/*     */ import org.eclipse.swt.widgets.Table;
/*     */ 
/*     */ public class FieldPositionEditingSupport extends EditingSupport
/*     */ {
/*     */   private CellEditor editor;
/*     */   private boolean down;
/*     */ 
/*     */   public FieldPositionEditingSupport(ColumnViewer viewer, boolean down)
/*     */   {
/*  41 */     super(viewer);
/*     */ 
/*  43 */     this.down = down;
/*     */ 
/*  45 */     this.editor = new CheckboxCellEditor(((TableViewer)viewer).getTable());
/*     */   }
/*     */ 
/*     */   protected boolean canEdit(Object element)
/*     */   {
/*  50 */     Field field = (Field)element;
/*  51 */     Entity entity = field.getEntity();
/*     */ 
/*  53 */     int position0 = -1;
/*  54 */     int position1 = -1;
/*     */ 
/*  56 */     List fieldList = entity.getFieldList();
/*  57 */     for (int i = 0; i < fieldList.size(); i++) {
/*  58 */       Field f = (Field)fieldList.get(i);
/*     */ 
/*  60 */       if (f == field) {
/*  61 */         position0 = i;
/*     */ 
/*  63 */         if (this.down)
/*  64 */           position1 = i + 1;
/*     */         else {
/*  66 */           position1 = i - 1;
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/*  71 */     return (position0 >= 0) && (position0 < fieldList.size()) && (position1 >= 0) && (position1 < fieldList.size());
/*     */   }
/*     */ 
/*     */   protected CellEditor getCellEditor(Object element)
/*     */   {
/*  76 */     return this.editor;
/*     */   }
/*     */ 
/*     */   protected Object getValue(Object element)
/*     */   {
/*  81 */     return Boolean.valueOf(true);
/*     */   }
/*     */ 
/*     */   protected void setValue(Object element, Object value)
/*     */   {
/*  86 */     Field field = (Field)element;
/*  87 */     Entity entity = field.getEntity();
/*     */ 
/*  89 */     int position0 = -1;
/*  90 */     int position1 = -1;
/*     */ 
/*  92 */     List fieldList = entity.getFieldList();
/*  93 */     for (int i = 0; i < fieldList.size(); i++) {
/*  94 */       Field f = (Field)fieldList.get(i);
/*     */ 
/*  96 */       if (f == field) {
/*  97 */         position0 = i;
/*     */ 
/*  99 */         if (this.down)
/* 100 */           position1 = i + 1;
/*     */         else {
/* 102 */           position1 = i - 1;
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 107 */     if ((position0 >= 0) && (position0 < fieldList.size()) && (position1 >= 0) && (position1 < fieldList.size())) {
/* 108 */       List tempFieldList = new ArrayList();
/* 109 */       tempFieldList.addAll(fieldList);
/*     */ 
/* 111 */       List list = new ArrayList();
/* 112 */       for (int i = 0; i < tempFieldList.size(); i++) {
/* 113 */         if (i == position0) {
/* 114 */           list.add((Field)tempFieldList.get(position1));
/*     */         }
/* 116 */         else if (i == position1) {
/* 117 */           list.add((Field)tempFieldList.get(position0));
/*     */         }
/*     */         else {
/* 120 */           list.add((Field)tempFieldList.get(i));
/*     */         }
/*     */       }
/*     */ 
/* 124 */       entity.setFieldList(list);
/* 125 */       getViewer().setInput(entity.getFieldList());
/*     */ 
/* 127 */       ((TableViewer)getViewer()).getTable().setSelection(position1);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.support.FieldPositionEditingSupport
 * JD-Core Version:    0.6.0
 */